package com.unlcn.ils.kas.controller.order;

import com.unlcn.ils.kas.annotation.LogRecord;
import com.unlcn.ils.kas.service.order.ImportService;
import com.unlcn.ils.kas.service.util.enums.CommonExceptionEnum;
import com.unlcn.ils.kas.vo.RestVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 导入接口
 * 
 * @author 罗必量
 */
@RestController
@RequestMapping("/import")
public class ImportController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ImportController.class);

    @Autowired
    private ImportService importService;

    /**
     * 导入订单
     * 
     * @param data
     * @return
     */
    @LogRecord(description = "导入订单信息")
    @PostMapping("/importOrder")
    public RestVO<Map<String, Object>> importOrder(@RequestBody String data) {
        LOGGER.error("ImportController.importOrder（导入订单信息） params : {} ", data);

        RestVO<Map<String, Object>> restVO = null;

        try {
            if (StringUtils.isEmpty(data)) {
                return null;
            }

            restVO = new RestVO(CommonExceptionEnum.SUCCESS.getCode(), importService.importOrder(data),
                    CommonExceptionEnum.SUCCESS.getText());
        } catch (Exception e) {
            LOGGER.error("OrderController.queryPage ERROR Message : {} ", e);
            restVO = new RestVO<>(CommonExceptionEnum.ERROR.getCode(), CommonExceptionEnum.ERROR.getText());
        }

        return restVO;
    }

    @LogRecord(description = "导入在途轨迹")
    @PostMapping("/importOnway")
    public RestVO<Map<String, Object>> importOnway(@RequestBody String data) {
        LOGGER.error("ImportController.importOrder（导入在途轨迹信息） params : {} ", data);

        RestVO<Map<String, Object>> restVO = null;

        try {
            if (StringUtils.isEmpty(data)) {
                return null;
            }

            restVO = new RestVO(CommonExceptionEnum.SUCCESS.getCode(), importService.importOnway(data),
                    CommonExceptionEnum.SUCCESS.getText());
        } catch (Exception e) {
            LOGGER.error("OrderController.queryPage ERROR Message : {} ", e);
            restVO = new RestVO<>(CommonExceptionEnum.ERROR.getCode(), CommonExceptionEnum.ERROR.getText());
        }

        return restVO;
    }
}
